package com.xiaohao.student_course.controller;

import com.xiaohao.student_course.bean.Student;
import com.xiaohao.student_course.bean.StudentQueryPage;
import com.xiaohao.student_course.bean.StudentQueryParam;
import com.xiaohao.student_course.service.MajorService;
import com.xiaohao.student_course.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 *
 * @author 小浩
 * @date 2018-12-11 16:26
 * @package com.xiaohao.student_course.controller
 * @description
 */
@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;
    @Autowired
    private MajorService majorService;

    @RequestMapping("/select_all")
    @ResponseBody
    public String selectAll(){
        return "success";
    }


    @RequestMapping("/student-query")
    public String studentQuery(StudentQueryParam studentQueryParam, Model model){
        studentQueryParam.setPageSize(100);
        studentQueryParam.setPageNumber(0);
        StudentQueryPage studentQueryPage=new StudentQueryPage();

        Page<Student> page = studentService.studentQuery(studentQueryParam);
        studentQueryPage.setStudentList(page.getContent());
        studentQueryPage.setPageTotle(page.getTotalPages());
        studentQueryPage.setPageSize(page.getSize());
        studentQueryPage.setPageNumber(page.getNumber());
        studentQueryPage.setTotle(page.getTotalElements());
        studentQueryPage.setMajorname(majorService.getAllMajorName());
        model.addAttribute("studentQueryPage",studentQueryPage);
        return "student-query";
    }

}
